#include<stdio.h>
int main(){
	int year,month,month1[12]={31,28,31,30,31,30,31,31,30,31,30,31},month2[12]={31,29,31,30,31,30,31,31,30,31,30,31},day;
	int i,n,t;
	scanf("%d",&n);
	for(t=1;t<=n;t++){
	int m=0;
	scanf("%d%d%d",&year,&month,&day);
	if((year%4==0&&year%100!=0)||(year%400==0)){
	for(i=0;i<month-1;i++){
		m+=month2[i];
	}
	printf("%d\n",m+day);
}
	else{
	for(i=0;i<month-1;i++){
		m+=month1[i];
	}
	printf("%d\n",m+day);
}
}
} 
